libc: retry open when interrupted#252
Conversation
| loop { | ||
| let fd = open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC); | ||
| if fd < 0 { | ||
| let err = last_os_error(); | ||
| // We should try again if the call was interrupted. | ||
| if err.raw_os_error() != Some(libc::EINTR) { | ||
| return Err(err); | ||
| } | ||
| } else { | ||
| return Ok(fd); | ||
| } |
There was a problem hiding this comment.
I'm wondering if it's more idiomatic to do:
let mut fd;
while { fd = open(...); fd < 0 } {
let err = last_os_error();
// We should try again if open() was interrupted.
if err.raw_os_error() != Some(libc::EINTR) {
return Err(err);
}
}
Ok(fd)There was a problem hiding this comment.
Alternatively:
loop {
let fd = open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC);
if fd >= 0 {
return Ok(fd);
}
let err = las_os_error();
// We should try again if open() was interrupted.
if err.raw_os_error() != Some(libc::EINTR) {
return Err(err);
}
}There was a problem hiding this comment.
I have taken the second version, which received a thumbs up. :)
The open call can be interrupted. Since sys_fill_exact covers this for read operation already, it should be done here as well. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
|
I'll give @newpavlov a little time to take a look, and then I'll merge this. |
newpavlov
left a comment
There was a problem hiding this comment.
I wonder if it could be worth to limit number of retries to be extra safe by replacing loop { .. } with something like this:
for _ in 0..256 {
// ..
}
Err(Error::TOO_MANY_ITERATIONS) // find a better name
It looks like Rust's |
The open call can be interrupted. Since sys_fill_exact covers this for read operation already, it should be done here as well. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
The open call can be interrupted. Since sys_fill_exact covers this for read operation already, it should be done here as well. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
The open call can be interrupted. Since sys_fill_exact covers this for
read operation already, it should be done here as well.
Signed-off-by: Tobias Stoeckmann tobias@stoeckmann.org
Shoutout to c3h2-ctf.